package com.ala4.oxcafe.controller;

import com.ala4.oxcafe.boot.ExcelExport;
import com.ala4.oxcafe.boot.page.PageDomain;
import com.ala4.oxcafe.boot.page.PageResult;
import com.ala4.oxcafe.domain.R;
import com.ala4.oxcafe.dto.ServiceAuditDTO;
import com.ala4.oxcafe.entity.ServiceOrder;
import com.ala4.oxcafe.service.ServiceOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务单管理
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/15 12:04
 */
@Slf4j
@RestController
@RequestMapping("/service-order")
@AllArgsConstructor
@Tag(name = "服务单管理", description = "用于管理服务单")
public class ServiceOrderController {

    private final ServiceOrderService serviceOrderService;

    @Operation(summary = "分页查询服务单")
    @GetMapping("/page")
    public R<PageResult<ServiceOrder>> page(PageDomain pageDomain, ServiceOrder serviceOrder) {
        return R.ok(PageResult.iPage(serviceOrderService.serviceOrderPage(pageDomain, serviceOrder)));
    }

    @Operation(summary = "导出服务单")
    @GetMapping("/export")
    @ExcelExport(value = ServiceOrder.class)
    public R<PageResult<ServiceOrder>> export(PageDomain pageDomain, ServiceOrder serviceOrder) {
        return R.ok(PageResult.iPage(serviceOrderService.serviceOrderPage(pageDomain, serviceOrder)));
    }

    @Operation(summary = "列表查询服务单")
    @GetMapping("/list")
    public R<List<ServiceOrder>> list(ServiceOrder serviceOrder) {
        return R.ok(serviceOrderService.serviceOrderList(serviceOrder));
    }

    @Operation(summary = "创建服务单")
    @PostMapping("/create")
    public R<ServiceOrder> create(@RequestBody @Validated ServiceOrder serviceOrder) {
        return R.ok(serviceOrderService.createServiceOrder(serviceOrder));
    }

    @Operation(summary = "更新服务单")
    @PutMapping("/update")
    public R<ServiceOrder> update(@RequestBody @Validated ServiceOrder serviceOrder) {
        return R.ok(serviceOrderService.updateServiceOrder(serviceOrder));
    }

    @Operation(summary = "服务单详情")
    @GetMapping("/{serviceId}")
    public R<ServiceOrder> info(@PathVariable Long serviceId) {
        return R.ok(serviceOrderService.serviceOrderInfo(serviceId));
    }

    @Operation(summary = "服务单审核")
    @PutMapping("/audit")
    public R<ServiceOrder> audit(@RequestBody ServiceAuditDTO serviceAuditDTO) {
        return R.ok(serviceOrderService.audit(serviceAuditDTO));
    }

}
